package com.erp.common.config;

import com.erp.common.ex.ErpException;
import com.erp.common.result.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 处理自定义的异常
     * @param exception
     * @return
     */
    @ExceptionHandler(ErpException.class)
    public Result erpException(ErpException exception){
        exception.printStackTrace();
        return Result.fail(exception.getMessage());
    }

    /**
     * 兜底异常
     * @param exception
     * @return
     */
    @ExceptionHandler(Exception.class)
    public Result exception(Exception exception) {
        exception.printStackTrace();
        return Result.fail(exception.getMessage());
    }


}
